<script>
	import {
		getConfigJson
	} from "api/appapi.js"
	export default {
		globalData: {
			config: {},
			versionNumber: 'V2.2.3',
			buildVersionNumber: 'V2.2.3.20240208',
			channelVersionNumber: 'V2.2.3', //Public.IOS.V2.1.0   Public.IOSTF.V2.1.0  Public.HW.V2.1.0   Public.MI.V2.1.0
			systemBarHeight: 0,
			systemInfo: {},
			menuButtonInfo: {},
			windowInfo: {},
			//BASE_URL: "https://wx.2024csnl.com", //测试域名
			BASE_URL: "https://wx.2024csnl.com", //正式域名 https://app.sappsa.top
			HOME_PAGE: '/pages/tab/home',
			isAgency: true, //是否走代理打包h5前须改为false
		},
		onShow: function(opt) {
			// var args = plus.runtime.arguments;
			// if (args) {
			// 	// 处理args参数，如直达到某新页面等
			// 	if (args.startsWith("tab")) {
			// 		uni.switchTab({
			// 			url: args.substring(3, args.length)
			// 		})
			// 	}
			// 	if (args.startsWith("page")) {
			// 		uni.navigateTo({
			// 			url: args.substring(4, args.length)
			// 		})
			// 	}
			// }
		},
		async onLaunch() {
			// for (var i = 0; i < 7; i++) {
			// 	uni.setTabBarItem({
			// 		index: i,
			// 		visible: false
			// 	})
			// }

			uni.getSystemInfo({
				success: res => {
					this.globalData.systemInfo = res;
					this.globalData.systemBarHeight = res.statusBarHeight;
				}
			})
			this.globalData.menuButtonInfo = uni.getMenuButtonBoundingClientRect();
			this.globalData.windowInfo = uni.getWindowInfo();

			var BASE_URL = this.globalData.BASE_URL
			var platform = 'app'
			const isAgency = this.globalData.isAgency

			// #ifdef H5
			platform = 'h5'
			if (isAgency) {
				BASE_URL = '/api'
			}
			// #endif

			try {
				const testAccountRes = await getConfigJson(
					`${BASE_URL}/app/config/config.test.account.json`)

				const testAccountData = testAccountRes.data

				if (testAccountData.status == 1) {
					uni.setStorageSync('TESTACCOUNT', JSON.stringify(testAccountData.data));
				}

				let isLogin = '.anon';
				try {
					const sessionData = uni.getStorageSync('sessionData')
					if (sessionData && sessionData.session_id) {
						isLogin = '';
						if (sessionData.account) {
							if (testAccountData.data.indexOf(sessionData.account) >= 0) {
								isLogin = '.anon';
							}
						}
					}
				} catch (e) {}

				const jsonUrl = `${BASE_URL}/app/config/config.${this.globalData.channelVersionNumber}${isLogin}.json`;

				// #ifdef H5
				jsonUrl = `${BASE_URL}/app/config/config.${this.globalData.channelVersionNumber}.json`;
				// #endif

				const res = await getConfigJson(`${jsonUrl}`)
				const {
					data,
					status,
					msg
				} = res.data

				if (status == 1) {
					this.globalData.config = data;
					uni.setStorageSync('APPCONFIG', JSON.stringify(data));

					if (!data.isTabbar1) {
						//uni.setTabBarItem({
						//	index: 0,
						//	visible: false
						//})
					} else {
						//uni.setTabBarItem({
						//	index: 0,
						//	visible: true
						//})
					}

					if (!data.homePath) {
						this.globalData.HOME_PAGE = data.homePath
					} else {
						this.globalData.HOME_PAGE = "/pages/tab/home"
					}

					if (!data.isTabbar2) {
						// uni.setTabBarItem({
						// 	index: 1,
						// 	visible: false
						// })
					} else {
						// uni.setTabBarItem({
						// 	index: 1,
						// 	visible: true
						// })
					}


					// if (!data.isTabbar3) {
					// 	uni.setTabBarItem({
					// 		index: 2,
					// 		visible: false
					// 	})
					// } else {
					// 	uni.setTabBarItem({
					// 		index: 2,
					// 		visible: true
					// 	})
					// }

					// if (!data.isTabbar4) {
					// 	uni.setTabBarItem({
					// 		index: 3,
					// 		visible: false
					// 	})
					// } else {
					// 	uni.setTabBarItem({
					// 		index: 3,
					// 		visible: true
					// 	})
					// }


					// if (!data.isTabbar5) {
					// 	uni.setTabBarItem({
					// 		index: 4,
					// 		visible: false
					// 	})
					// } else {
					// 	uni.setTabBarItem({
					// 		index: 4,
					// 		visible: true
					// 	})
					// }


					// if (!data.isTabbar6) {
					// 	uni.setTabBarItem({
					// 		index: 5,
					// 		visible: false
					// 	})
					// } else {
					// 	uni.setTabBarItem({
					// 		index: 5,
					// 		visible: true
					// 	})
					// }

					// if (!data.isTabbar7) {
					// 	uni.setTabBarItem({
					// 		index: 6,
					// 		visible: false
					// 	})
					// } else {
					// 	uni.setTabBarItem({
					// 		index: 6,
					// 		visible: true
					// 	})
					// }
				}
			} catch (e) {
				uni.hideLoading()
			}

			var getParam = function(path, name) {
				var reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)", "i");
				if (reg.test(path))
					return unescape(RegExp.$2.replace(/\+/g, " "));
				return "";
			};

			uni.onTabBarMidButtonTap((e) => {
				uni.scanCode({
					onlyFromCamera: true,
					autoZoom: false,
					success: (res) => {
						setTimeout(() => {
							const bid = getParam(res.result, "bid");
							const bindbid = getParam(res.result, "bindbid");
							if (bid != '' || bindbid != '') {
								uni.navigateTo({
									url: `/business/pages/business_tab/qrCodePay?bid=${bid}&bindbid=${bindbid}`
								})
							} else {
								uni.showToast({
									title: '无效二维码'
								});
							}
						}, 800)
					}
				});
			})
		},
		onShow: function() {},
		onHide: function() {}
	}
</script>


<style lang="scss">
	/* #ifdef H5 */
	uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
		/* 隐藏滚动条，但依旧具备可以滚动的功能 */
		display: none;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
		color: transparent;
	}

	/* #endif */
	/*每个页面公共css */
	/* 设置圆角 */
	/* #ifndef APP-NVUE */
	checkbox.round .wx-checkbox-input,
	checkbox.round .uni-checkbox-input {
		border-radius: 100upx;
	}

	/* 设置背景色 */
	checkbox.red[checked] .wx-checkbox-input,
	checkbox.red.checked .uni-checkbox-input {
		background-color: #41644A !important;
		border-color: #41644A !important;
		color: #ffffff !important;
	}

	/* #endif */

	.wx-progress-inner-bar {
		border-radius: 6px !important;
		background-image: linear-gradient(to right, #e9b87a, #f8d9ad);
	}


	.flex,
	.between,
	.around,
	.column {
		display: flex;
		flex-direction: row;
	}

	.column {
		flex-direction: column;
	}

	.flex-center {
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.align {
		align-items: center;
	}

	.flex-end {
		align-items: flex-end;
	}

	.flex-start {
		align-items: flex-start;
	}

	.between {
		justify-content: space-between;
	}

	.around {
		justify-content: space-around;
	}

	.center {
		justify-content: center;
	}

	.into {
		width: 11rpx;
		height: 20rpx;
	}

	.fl {
		flex: 1;
	}

	/* #ifndef APP-NVUE */
	.tab-hig {
		display: block;
		height: 180rpx;
	}

	.font-l {
		text-transform: uppercase;
	}

	/* #endif */



	.c-blue {
		color: #27D1DC;
	}

	.c-red {
		color: #F41717;
	}

	.c-gray {
		color: #B3B3B3;
	}

	.c-black {
		color: #000;
	}

	.fw-b {
		font-weight: bold;
	}

	/* #ifndef APP-NVUE */
	.safety {
		box-sizing: border-box;
		line-height: 1.4;
		height: 100%;
		// 设置头部安全距离
		// padding-top: var(--status-bar-height);
		padding-top: 1rpx;
	}


	.ws-n {
		white-space: nowrap;
	}

	/* #endif */
</style>